home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bluep.swf / scripts / __Packages / mx / transitions / Tween.as < prev   
Encoding:
Text File  |  2013-04-24  |  5.1 KB  |  244 lines

  1. class mx.transitions.Tween
  2. {
  3.    var obj;
  4.    var prop;
  5.    var begin;
  6.    var useSeconds;
  7.    var _listeners;
  8.    var addListener;
  9.    var prevTime;
  10.    var _time;
  11.    var looping;
  12.    var _duration;
  13.    var broadcastMessage;
  14.    var isPlaying;
  15.    var _fps;
  16.    var prevPos;
  17.    var _pos;
  18.    var change;
  19.    var _intervalID;
  20.    var _startTime;
  21.    static var version = "1.1.0.52";
  22.    static var __initBeacon = mx.transitions.OnEnterFrameBeacon.init();
  23.    static var __initBroadcaster = mx.transitions.BroadcasterMX.initialize(mx.transitions.Tween.prototype,true);
  24.    function Tween(obj, prop, func, begin, finish, duration, useSeconds)
  25.    {
  26.       mx.transitions.OnEnterFrameBeacon.init();
  27.       if(!arguments.length)
  28.       {
  29.          return;
  30.       }
  31.       this.obj = obj;
  32.       this.prop = prop;
  33.       this.begin = begin;
  34.       this.position = begin;
  35.       this.duration = duration;
  36.       this.useSeconds = useSeconds;
  37.       if(func)
  38.       {
  39.          this.func = func;
  40.       }
  41.       this.finish = finish;
  42.       this._listeners = [];
  43.       this.addListener(this);
  44.       this.start();
  45.    }
  46.    function set time(t)
  47.    {
  48.       this.prevTime = this._time;
  49.       if(t > this.duration)
  50.       {
  51.          if(this.looping)
  52.          {
  53.             this.rewind(t - this._duration);
  54.             this.update();
  55.             this.broadcastMessage("onMotionLooped",this);
  56.          }
  57.          else
  58.          {
  59.             if(this.useSeconds)
  60.             {
  61.                this._time = this._duration;
  62.                this.update();
  63.             }
  64.             this.stop();
  65.             this.broadcastMessage("onMotionFinished",this);
  66.          }
  67.       }
  68.       else if(t < 0)
  69.       {
  70.          this.rewind();
  71.          this.update();
  72.       }
  73.       else
  74.       {
  75.          this._time = t;
  76.          this.update();
  77.       }
  78.    }
  79.    function get time()
  80.    {
  81.       return this._time;
  82.    }
  83.    function set duration(d)
  84.    {
  85.       this._duration = !(d == null || d <= 0) ? d : _global.Infinity;
  86.    }
  87.    function get duration()
  88.    {
  89.       return this._duration;
  90.    }
  91.    function set FPS(fps)
  92.    {
  93.       var _loc2_ = this.isPlaying;
  94.       this.stopEnterFrame();
  95.       this._fps = fps;
  96.       if(_loc2_)
  97.       {
  98.          this.startEnterFrame();
  99.       }
  100.    }
  101.    function get FPS()
  102.    {
  103.       return this._fps;
  104.    }
  105.    function set position(p)
  106.    {
  107.       this.setPosition(p);
  108.    }
  109.    function setPosition(p)
  110.    {
  111.       this.prevPos = this._pos;
  112.       this.obj[this.prop] = this._pos = p;
  113.       this.broadcastMessage("onMotionChanged",this,this._pos);
  114.       updateAfterEvent();
  115.    }
  116.    function get position()
  117.    {
  118.       return this.getPosition();
  119.    }
  120.    function getPosition(t)
  121.    {
  122.       if(t == undefined)
  123.       {
  124.          t = this._time;
  125.       }
  126.       return this.func(t,this.begin,this.change,this._duration);
  127.    }
  128.    function set finish(f)
  129.    {
  130.       this.change = f - this.begin;
  131.    }
  132.    function get finish()
  133.    {
  134.       return this.begin + this.change;
  135.    }
  136.    function continueTo(finish, duration)
  137.    {
  138.       this.begin = this.position;
  139.       this.finish = finish;
  140.       if(duration != undefined)
  141.       {
  142.          this.duration = duration;
  143.       }
  144.       this.start();
  145.    }
  146.    function yoyo()
  147.    {
  148.       this.continueTo(this.begin,this.time);
  149.    }
  150.    function startEnterFrame()
  151.    {
  152.       if(this._fps == undefined)
  153.       {
  154.          _global.MovieClip.addListener(this);
  155.       }
  156.       else
  157.       {
  158.          this._intervalID = setInterval(this,"onEnterFrame",1000 / this._fps);
  159.       }
  160.       this.isPlaying = true;
  161.    }
  162.    function stopEnterFrame()
  163.    {
  164.       if(this._fps == undefined)
  165.       {
  166.          _global.MovieClip.removeListener(this);
  167.       }
  168.       else
  169.       {
  170.          clearInterval(this._intervalID);
  171.       }
  172.       this.isPlaying = false;
  173.    }
  174.    function start()
  175.    {
  176.       this.rewind();
  177.       this.startEnterFrame();
  178.       this.broadcastMessage("onMotionStarted",this);
  179.    }
  180.    function stop()
  181.    {
  182.       this.stopEnterFrame();
  183.       this.broadcastMessage("onMotionStopped",this);
  184.    }
  185.    function resume()
  186.    {
  187.       this.fixTime();
  188.       this.startEnterFrame();
  189.       this.broadcastMessage("onMotionResumed",this);
  190.    }
  191.    function rewind(t)
  192.    {
  193.       this._time = t != undefined ? t : 0;
  194.       this.fixTime();
  195.       this.update();
  196.    }
  197.    function fforward()
  198.    {
  199.       this.time = this._duration;
  200.       this.fixTime();
  201.    }
  202.    function nextFrame()
  203.    {
  204.       if(this.useSeconds)
  205.       {
  206.          this.time = (getTimer() - this._startTime) / 1000;
  207.       }
  208.       else
  209.       {
  210.          this.time = this._time + 1;
  211.       }
  212.    }
  213.    function onEnterFrame()
  214.    {
  215.       this.nextFrame();
  216.    }
  217.    function prevFrame()
  218.    {
  219.       if(!this.useSeconds)
  220.       {
  221.          this.time = this._time - 1;
  222.       }
  223.    }
  224.    function toString()
  225.    {
  226.       return "[Tween]";
  227.    }
  228.    function fixTime()
  229.    {
  230.       if(this.useSeconds)
  231.       {
  232.          this._startTime = getTimer() - this._time * 1000;
  233.       }
  234.    }
  235.    function update()
  236.    {
  237.       this.position = this.getPosition(this._time);
  238.    }
  239.    function func(t, b, c, d)
  240.    {
  241.       return c * t / d + b;
  242.    }
  243. }
  244.